<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var weChatLocationDataGrid${weChat.id};
    $(function() {
        weChatLocationDataGrid${weChat.id} = $('#weChatLocationDataGrid${weChat.id}').datagrid({
        url : '${path}/admin/weChatLocation/dataGrid',
        striped : true,
        rownumbers : true,
        pagination : true,
        idField : 'id',
        sortName : 'id',
        sortOrder : 'desc',
        pageSize : 20,
        pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
        frozenColumns : [ [
            <c:if test="${empty weChat}">
            {
                width : '50',
                title : '多选',
                field:'ck',
                checkbox:true 
            }
			,{
           	 	width : '70',
           	 	title : 'id',
           	 	field : 'id',
           	 	sortable : true,

			}
			,{
           	 	width : '270',
           	 	title : 'openId',
           	 	field : 'openId',
           	 	sortable : true,

			},
            </c:if>
			{
           	 	width : '100',
           	 	title : '纬度',
           	 	field : 'latitude',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '经度',
           	 	field : 'longitude',
           	 	sortable : true,

			}
			,{
           	 	width : '100',
           	 	title : '精度',
           	 	field : 'precision',
           	 	sortable : true,

			}
			,{
           	 	width : '450',
           	 	title : '坐标地址',
           	 	field : 'lable',
           	 	sortable : true,

			}
			,{
           	 	width : '150',
           	 	title : '创建时间',
           	 	field : 'createdTime',
           	 	sortable : true,

			}
			,{
            field : 'action',
            title : '操作',
            width : 200,
            formatter : function(value, row, index) {
                var str = '';
                <%--<shiro:hasPermission name="/admin/weChatLocation/edit">--%>
                    <%--str += $.formatString('<a href="javascript:void(0)" class="weChatLocation-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="weChatLocationEditFun${weChat.id}(\'{0}\');" >编辑</a>', row.id);--%>
                <%--</shiro:hasPermission>--%>
                <%--<shiro:hasPermission name="/admin/weChatLocation/delete">--%>
                <%--str += '&nbsp;&nbsp;|&nbsp;&nbsp;';--%>
                <%--str += $.formatString('<a href="javascript:void(0)" class="weChatLocation-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="weChatLocationDeleteFun(\'{0}\');" >删除</a>', row.id);--%>
                <%--</shiro:hasPermission>--%>

                str += $.formatString('<a href="javascript:void(0)" class="weChatLocation-easyui-linkbutton-getlocation" data-options="plain:true,iconCls:\'fi-target-two icon-green\'" onclick="weChatLocationGetLocationFun${weChat.id}(\'{0}\');" >获取位置</a>', row.id);
                str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                str += $.formatString('<a href="javascript:void(0)" class="weChatLocation-easyui-linkbutton-looklocation" data-options="plain:true,iconCls:\'fi-eye icon-yellow\'" onclick="weChatLocationLookLocationFun${weChat.id}(\'{0}\');" >查看位置</a>', row.id);

                return str;
            }
        	}
          ] ],
        singleSelect: false,
        selectOnCheck: true,
        checkOnSelect: true,
        onLoadSuccess:function(data){
            if(data){
                $.each(data.rows, function(index, item){
                    if(item.checked){
                        $('#contentDataGrid').datagrid('checkRow', index);
                    }
                });
            }
//            $('.weChatLocation-easyui-linkbutton-edit').linkbutton({text:'编辑'});
//            $('.weChatLocation-easyui-linkbutton-del').linkbutton({text:'删除'});
            $('.weChatLocation-easyui-linkbutton-getlocation').linkbutton({text:'获取位置'});
            $('.weChatLocation-easyui-linkbutton-looklocation').linkbutton({text:'查看位置'});


        },
        <c:if test="${empty weChat}">
        toolbar : '#weChatLocationToolbar',
        </c:if>
        queryParams: {"openId": "${weChat.openId}"}

    });
});

/**
 * 添加框
 * @param url
 */
function weChatLocationAddFun() {
    parent.$.modalDialog({
        title : '添加',
        width : "60%",
        height : "80%",
        href : '${path}/admin/weChatLocation/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = weChatLocationDataGrid${weChat.id};//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#weChatLocationAddForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 编辑
 */
function weChatLocationEditFun${weChat.id}(id) {
    if (id == undefined) {
        var rows = weChatLocationDataGrid${weChat.id}.datagrid('getSelections');
        id = rows[0].id;
    } else {
        weChatLocationDataGrid${weChat.id}.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : "60%",
        height : "80%",
        href :  '${path}/admin/weChatLocation/editPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = weChatLocationDataGrid${weChat.id};//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#weChatLocationEditForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 获取位置
 */
function weChatLocationGetLocationFun${weChat.id}(id) {
    progressLoad();
    $.post('${path}/admin/weChatLocation/getLocation', {
        id : id
    }, function(result) {
        if (result.success) {
//            parent.$.messager.alert('提示', result.msg, 'info');
            weChatLocationDataGrid${weChat.id}.datagrid('reload');
        }
        progressClose();
    }, 'JSON');
}

/**
 * 查看位置地图
 */
function weChatLocationLookLocationFun${weChat.id}(id) {
    layer.open({
        type: 2,
        title: '查看位置',
        shadeClose: true,
        shade: false,
        maxmin: true, //开启最大化最小化按钮
        area: ['893px', '600px'],
        content: '${path}/admin/weChatLocation/LookLocation?id=' + id
    });

}

<%--/**--%>
 <%--* 删除--%>
 <%--*/--%>
 <%--function weChatLocationDeleteFun(id) {--%>
     <%--if (id == undefined) {//点击右键菜单才会触发这个--%>
         <%--var rows = weChatLocationDataGrid${weChat.id}.datagrid('getSelections');--%>
         <%--id = rows[0].id;--%>
     <%--} else {//点击操作里面的删除图标会触发这个--%>
         <%--weChatLocationDataGrid${weChat.id}.datagrid('unselectAll').datagrid('uncheckAll');--%>
     <%--}--%>
     <%--parent.$.messager.confirm('询问', '您是否要删除当前数据？', function(b) {--%>
         <%--if (b) {--%>
             <%--progressLoad();--%>
             <%--$.post('${path}/admin/weChatLocation/delete', {--%>
                 <%--id : id--%>
             <%--}, function(result) {--%>
                 <%--if (result.success) {--%>
                     <%--parent.$.messager.alert('提示', result.msg, 'info');--%>
                     <%--weChatLocationDataGrid${weChat.id}.datagrid('reload');--%>
                 <%--}--%>
                 <%--progressClose();--%>
             <%--}, 'JSON');--%>
         <%--}--%>
     <%--});--%>
<%--}--%>

/**
 * 批量删除
 */
function weChatLocationDeleteIdsFun(){
	var ids = getweChatLocationSelectionsIds();
 	if(ids.length == 0){
 		$.messager.alert('提示','未选中数据!');
 		return ;
 	}
 	$.messager.confirm('确认','确定删除ID为 '+ids+' 的记录,共'+ids.split(",").length+'记录吗？',function(r){
 	    if (r){
 	    	var params = {"ids":ids};
         	$.post("${path}/admin/weChatLocation/deleteIds",params, function(result){
         		result=JSON.parse(result);
     			if(result.success){
     				parent.$.messager.alert('提示', result.msg, 'info');
                    weChatLocationDataGrid${weChat.id}.datagrid('reload');
     			}else{
     				$.messager.alert('错误提示',data.msg);
     			}
     		});
 	    }
 	});
}
/**
 * 获得选中的记录
 */
function getweChatLocationSelectionsIds(){
	var itemList = $("#weChatLocationDataGrid${weChat.id}");
	var sels = itemList.datagrid("getSelections");
	var ids = [];
	for(var i in sels){
		ids.push(sels[i].id);
	}
	ids = ids.join(",");
	sels.length=0;
	return ids;
}

/**
 * 清除
 */
function weChatLocationCleanFun() {
    $('#weChatLocationSearchForm input').val('');
    weChatLocationDataGrid${weChat.id}.datagrid('load', {});
}
/**
 * 搜索
 */
function weChatLocationSearchFun() {
     weChatLocationDataGrid${weChat.id}.datagrid('load', $.serializeObject($('#weChatLocationSearchForm')));
}
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" class="lay_box" style="height: 30px; overflow: hidden;background-color: #fff">
        <c:if test="${empty weChat}">
        <form id="weChatLocationSearchForm">
            <div class="tab_box">
                <div class="tab_a">
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="weChatLocationSearchFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="weChatLocationCleanFun();">清空</a>
                </div>
                <ul class="list">
					<li>
                        <label>openId:</label>
                        <input name="openId" type="text" placeholder="请输入openId" class="easyui-textbox" data-options="height:29,width:250"/>
                    </li>
					<li>
                        <label>坐标地址:</label>
                        <input name="lable" type="text" placeholder="请输入坐标地址" class="easyui-textbox" data-options="height:29,width:200"/>
                    </li>
                </ul>
            </div>
        </form>
        </c:if>
     </div>
    <div data-options="region:'center',border:false">
        <table id="weChatLocationDataGrid${weChat.id}" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="weChatLocationToolbar" style="display: none;">
    <shiro:hasPermission name="/admin/weChatLocation/add">
        <a onclick="weChatLocationAddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-page-add'">添加</a>
    </shiro:hasPermission>
        <shiro:hasPermission name="/admin/weChatLocation/deleteIds">
        <a onclick="weChatLocationDeleteIdsFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-x icon-red'">删除</a>
    </shiro:hasPermission>
</div>